package com.example.glidex;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ImageView mImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mImageView = findViewById(R.id.img);
        // 以百度搜索的Logo地址为例，下面所有地址中只有
        // https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png是正确的，
        // 其他地址都无法获取到图片
        List<String> urls = new ArrayList() {
            {
                add("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png");
                add("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d");
                add("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6");
                add("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6c");
                add("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf");
                add("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.p");
                add("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.pn");
            }
        };
        GlideApp.with(this.getApplicationContext())
                .load(new ImgUrlWrapper(urls))
                .skipMemoryCache(true)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .apply(new RequestOptions().dontAnimate())
                .placeholder(R.mipmap.ic_launcher)
                .into(mImageView);
    }
}